<?php
namespace App\Module\Pay\Controller;

use App\Common\Controller\AbstractController;
use App\Component\Wechat\WechatFactory;
use App\Module\Pay\Service\ActivityService;
use Hyperf\Di\Annotation\Inject;
use Symfony\Component\HttpFoundation\Request;

class NotifyController extends AbstractController{

    /**
     * @Inject()
     * @var WechatFactory $wechatFactory
     */
    private $wechatFactory;

    /**
     * @Inject()
     * @var ActivityService $activityService
     */
    private $activityService;

    public function wechatPayNotify(){
        $app = $this->wechatFactory->getPayment();
        $get = $this->request->getQueryParams();
        $post = $this->request->getParsedBody();
        $cookie = $this->request->getCookieParams();
        $files = $this->request->getUploadedFiles();
        $server = $this->request->getServerParams();
        $xml = $this->request->getBody()->getContents();

        $app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml);
        return $app->handlePaidNotify(function($message, $fail){
            $this->activityService->payUpdate($message['out_trade_no'],$message['transaction_id']);
            return true;
        });
    }

    public function wechatRefundNotify(){

    }
}